<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="城市编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cityCode">
              <a-input v-model="model.cityCode" placeholder="请输入城市编码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="城市名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cityName">
              <a-input v-model="model.cityName" placeholder="请输入城市名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工种类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="stationType">
              <a-input v-model="model.stationType" placeholder="请输入工种类型"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工种名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="stationName">
              <a-input v-model="model.stationName" placeholder="请输入工种名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="站点id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="siteId">
              <a-input v-model="model.siteId" placeholder="请输入站点id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="站点创建时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="siteCreateTime">
              <j-date placeholder="请选择站点创建时间" v-model="model.siteCreateTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="站点名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="siteName">
              <a-input v-model="model.siteName" placeholder="请输入站点名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="结算率" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rate">
              <a-input v-model="model.rate" placeholder="请输入结算率"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="价格" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="price">
              <a-input-number v-model="model.price" placeholder="请输入价格" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="人数差距 " :labelCol="labelCol" :wrapperCol="wrapperCol" prop="num">
              <a-input-number v-model="model.num" placeholder="请输入人数差距 " style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="crm劳动者" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="crmNum">
              <a-input-number v-model="model.crmNum" placeholder="请输入crm劳动者" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="上岗人数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ondutyNum">
              <a-input-number v-model="model.ondutyNum" placeholder="请输入上岗人数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注1" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-input v-model="model.remark" placeholder="请输入备注1"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="结算规则的IDs" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ruleIds">
              <a-input v-model="model.ruleIds" placeholder="请输入结算规则的IDs"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="人数奖励" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="personReward">
              <a-input v-model="model.personReward" placeholder="请输入人数奖励"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="人数奖励达成备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reachRemark">
              <a-input v-model="model.reachRemark" placeholder="请输入人数奖励达成备注"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="人数奖励池达成解释" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reachExplain">
              <a-input v-model="model.reachExplain" placeholder="请输入人数奖励池达成解释"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'SiteRankForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/bi/siteRank/add",
          edit: "/bi/siteRank/edit",
          queryById: "/bi/siteRank/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>